package com.cet.designapplication.mediator;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author NSOC
 */

@Component
public class Mediator extends AbstractMediator{

    public static Map<String, Map<String, AbstractCustomer>> customerInstance = new ConcurrentHashMap<>();

    @Override
    public void messageTransfer(String orderId, String targetCustomer, AbstractCustomer customer, String payResult) {

        if (customer instanceof Buyer) {
            AbstractCustomer buyer = customerInstance.get(orderId).get("buyer");
            System.out.println("朋友代付" + buyer.getCustomerName() + "转发 OrderId " + orderId + "到用户 " + targetCustomer + " 进行支付.");
        } else if (customer instanceof Payer) {
            AbstractCustomer payer = customerInstance.get(orderId).get("payer");
            System.out.println("代付完成：" + payer.getCustomerName() + " 完成 OrderId " + orderId + " 的支付。 通知 " + targetCustomer + "，支付结果：" + payResult);
        } else {
            throw new UnsupportedOperationException();
        }
    }
}
